import createSagaMiddleware from "redux-saga";
import { createStore, applyMiddleware } from "redux";
import concatReducer from "./reducers";

export default function configureStore(initialState) {
  const sagaMiddleware = createSagaMiddleware();
  return {
    // applyMiddlewares的作用：它是 Redux 的原生方法，作用是将所有中间件组成一个数组，依次执行。
    ...createStore(
      concatReducer,
      initialState,
      applyMiddleware(sagaMiddleware)
    ),
    // 动态执行 saga
    runSaga: sagaMiddleware.run,
  };
}
